
#include <time.h>

#include <iostream>

using namespace std;

#include <boost/lexical_cast.hpp>

static inline
std::string dump_timestamp(uint64_t timestamp)
{
	char buffer[256] = {0};
	::time_t sec = timestamp / (1000 * 1000);
	struct ::tm t;
	::localtime_r(&sec, &t);
	char *buf = buffer;
	std::size_t n = ::strftime(buf, 255, "%Y-%m-%d %H:%M:%S", &t);
	buf += n;
	const unsigned int us = timestamp % (1000 * 1000);
	const std::size_t left_size = 255 - n;
	n += ::snprintf(buf, left_size, " %06d", us);
	return std::string(buffer, n);
}

int main(int argc, char **argv)
{
	if(argc < 2)
	{
		cout << argv[0] << " <timestamp> [timestamp ...]" << endl;
	}

	for(int i = 1; i < argc; ++i)
	{
		const uint64_t timestamp = boost::lexical_cast<uint64_t>(argv[i]);
		const std::string str = dump_timestamp(timestamp);
		cout << timestamp << " - "
		     << str << " - " << str.size()
		     << endl;
	}
	cout << endl;

	return 0;
}
